var common = require('../../lib/common.js');
var url = require('../../config/url.js');

Page({
    onGotUserInfo: function (e) {
        var detail = e.detail;
        wx.login({
            success: function (res) {
                wx.getUserInfo({
                    success: function (userinfo) {
                        if (res.code) {
                            common.post(
                                url.login,
                                {
                                    iv: userinfo.iv,
                                    code: res.code,
                                    encryptedData: userinfo.encryptedData,
                                    signature: userinfo.signature,
                                },
                                function (result) {
                                    wx.switchTab({
                                        url: '/pages/index/index'
                                    });
                                },
                                function (result) {
                                    console.log(result);
                                });
                        } else {
                            console.log('登录失败！' + res.errMsg)
                        }
                    }
                });
            }
        });
    }
});
